﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using WinFormsApp1.Common;
using static WinFormsApp1.Leo.week02.SlaughteredAdd;

namespace WinFormsApp1.Leo.week02
{
    public partial class TareAdd : Form
    {
        public TareAdd()
        {
            InitializeComponent();
            GetUPCData();
        }

        //商品代号
        public async void GetUPCData()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<UPCDataser>>>(URLCommon.Url2, "/WeekListOne_Leo/GetUPCDataShow", HttpClientHelper.MethodType.GET, default);

            comboBox1.DataSource = items.Data;
            comboBox1.DisplayMember = "UPCDataName";
            comboBox1.ValueMember = "GoodsMinuteId";

            this.Controls.Add(comboBox1);
        }

        public class UPCDataser
        {
            public int GoodsMinuteId { get; set; }
            public string UPCDataName { get; set; }
        }

        public record Taresa(int GoodsMinuteId, string TareMeasure, string TareStandardWeight, bool TareStatus, string TareRemark, bool IsDisable, bool IsDelete);

        private async void button1_Click(object sender, EventArgs e)
        {
            var GoodsMinuteId = Convert.ToInt32(comboBox1.SelectedValue);
            var TareMeasure = textBox1.Text;
            var TareStandardWeight = textBox2.Text;
            var TareStatus = true;
            var TareRemark = textBox3.Text;
            var IsDisable = true;
            var IsDelete = false;



            Taresa clients = new(GoodsMinuteId, TareMeasure, TareStandardWeight, TareStatus, TareRemark, IsDisable, IsDelete);
            var res = await HttpClientHelper.RequestUrl<Taresa, ApiResult<Tarees>>(URLCommon.Url1, "/WorkList01_leo/GetTareAdd", HttpClientHelper.MethodType.POST, clients);
            if (res.Code == 1)
            {
                MessageBox.Show("添加成功");
            }
        }

        public class Tarees
        {
            public int TareId { get; set; }
            /// <summary>
            /// 商品代号
            /// </summary>
            public int GoodsMinuteId { get; set; }

            /// <summary>
            /// 计量单位
            /// </summary>
            public string TareMeasure { get; set; }

            /// <summary>
            /// 标准重量
            /// </summary>
            public string TareStandardWeight { get; set; }

            /// <summary>
            /// 使用状态
            /// </summary>
            public bool TareStatus { get; set; } = true;

            /// <summary>
            /// 备注
            /// </summary>
            public string TareRemark { get; set; }

            /// <summary>
            /// 是否禁用
            /// </summary>
            public bool IsDisable { get; set; }

            /// <summary>
            /// 是否删除
            /// </summary>
            public bool IsDelete { get; set; } = false;
        }
    }
}
